<template>
  <div class="app-container">
    <div class="filter-container">
      
      <el-input clearable v-model="search.name" placeholder="配件"  style="width: 170px; margin-left: 10px"></el-input>
      <el-date-picker v-model="search.daterange" type="daterange" range-separator="至"
        start-placeholder="开始日期" end-placeholder="结束日期">
      </el-date-picker>
      <el-button type="primary" icon="el-icon-search"  @click="searchClick()" style="margin-left: 10px">查询</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" border
      fit highlight-current-row stripe style="width: 100%">
      <el-table-column align="center" label="序" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row._id }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="100" align="center" label="配件名称">
        <template slot-scope="scope">
          <span>{{ scope.row.partname }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="100" align="center" label="总数量">
        <template slot-scope="scope">
          <span>{{ scope.row.count }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="100" align="center" label="合计金额">
        <template slot-scope="scope">
          <span>{{ scope.row.totalmoney }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="100" align="center" label="付款类型">
        <template slot-scope="scope">
          <span>{{ scope.row.paytype }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="100" align="center" label="收款状态">
        <template slot-scope="scope">
          <span>{{ scope.row.collectstate }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="100" align="center" label="制单人">
        <template slot-scope="scope">
          <span>{{ scope.row.guider }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="100" align="center" label="日期">
        <template slot-scope="scope">
          <span>{{ scope.row.createtime | parseTime("{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作" width="220" fixed="right">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="tableRowClick().refund(scope.row.id)">退货</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page"  :limit.sync="listQuery.rows" @pagination="fetchData"/>

<!-- 退货 -->
    <el-dialog :title="dialogRefund.title" :visible.sync="dialogRefund.visible" width="700px">
      <div class="ci">
        <div class="bill" ref="dialogRefundBill">
          <div class="item">1、摘要：支付******供应商车款 已支付</div>
          <div class="item">2、科目：</div>
          <div class="item">借1：113200n 预付账款-***单位 金额=23409.00元</div>
          <div class="item">
            贷1：113300n 中国银行 36月按揭贷款 金额=360000.00元
          </div>
          <div class="item">贷2：融资支付 210100n 金额=360000.00元</div>
          <div class="item">
            贷3：厂家返利支付， 1133 单位：**** 金额=360000.00元
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogRefund.visible = false">取 消</el-button>
        <el-button type="primary"   @click="dialogRefundClick().save()" :loading="dialogRefund.saveloading">保 存</el-button>
      </div>
    </el-dialog>
<!-- end 退货 -->





 
  </div>
</template>

<script>
import * as partsApi from '@/api/finance/parts'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import * as enumHelper from '@/utils/enum'

export default {
    components: { Pagination },
    data(){
        return{
          search:{ 
              number:'',
              customer:'',
              phone:'',
              daterange:'',
              filtercomplete:true,
          },
          listQuery: {
                page: 1,
                rows: 20,
                name:'',
                phone:'',
                state:-1,
                daterange:''
          },
          list:null,
          listLoading:false,
          total:0,
          selectOptions:{
            paytype:[]
          },
          dialogRefund:{
              visible:false,
              saveloading:false,
              title:'退货',
              data:{

              }
          },
          dialogCredit:{
            visible:false,
            saveloading:false,
            title:'挂账收款',
            step:1,
            data:{

            }
          },
          
       }
    
    },
    created(){
        var that=this;
        //初始化下拉菜单
        //enumHelper.initOptions(that.selectOptions.salesState,enumHelper.presale.salesState);
        that.fetchData();
    },
    filters:{
      parseFixType(val){
        return enumHelper.aftersale.fixType.getName(val);
      },
      parseFixCategory(val){
        return enumHelper.aftersale.fixCategory.getName(val);
      },
      parseSettlementState(val){
        return enumHelper.aftersale.settlementState.getName(val);
      }

    },
    methods:{
        fetchData(){
          var that=this;
            partsApi.getPartsaleList({}).then(res=>{
              if(res.data){
                that.list=[...res.data.items.map((item,index)=>{
                  item._id=index+1;
                  return item;
                })];
              }
            })
        },
        refreshClick(){
          this.fetchData();
        },
        
        tableRowClick(){
            var that=this;
            return {
                refund(id){
                    that.dialogRefund.visible=true;
                },
                credit(id){
                    that.dialogCredit.visible=true;
                },
            }
        },
        dialogRefundClick(){
            var that=this;
            var dg=that.dialogRefund;
            return {
                save(){

                }
            }
        },
        dialogCreditClick(){
            var that=this;
            var dg=that.dialogCredit;
            return {
                save(){

                }
            }
        },
        dialogPrepayClick(){
            var that=this;
            var dg=that.dialogPrepay;
            var printHandle=null;
            return {
                save(){
                    dg.step=2;
                },
                print(){
                    if(!printHandle){
                        printHandle=new Print(that.$refs['dialogPayBill']);
                    }
                    printHandle.Start();
                }
            }
        },
        dialogReceiptClick(){
            var that=this;
            var dg=that.dialogReceipt;
            var printHandle=null;
            return {
                save(){},
                print(){
                    if(!printHandle){
                        printHandle=new Print(that.$refs['dialogReceiptBill']);
                    }
                    printHandle.Start();
                }
            }
        },
        
    }
}
</script>

<style>
</style>